package com.itcncp.wechat.app.rpc.service.impl;

import com.itcncp.common.annotation.BaseService;
import com.itcncp.common.base.BaseServiceImpl;
import com.itcncp.wechat.app.dao.mapper.ItcsTransJnlMapper;
import com.itcncp.wechat.app.dao.mapper.UserInvoiceOpJnlMapper;
import com.itcncp.wechat.app.dao.model.ItcsTransJnl;
import com.itcncp.wechat.app.dao.model.ItcsTransJnlExample;
import com.itcncp.wechat.app.dao.model.UserInvoiceOpJnl;
import com.itcncp.wechat.app.dao.model.UserInvoiceOpJnlExample;
import com.itcncp.wechat.app.rpc.api.UserInvoiceOpJnlService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
* UserInvoiceOpJnlService实现
* Created by itcncp on 2018/1/12.
*/
@Service
@Transactional
@BaseService
public class UserInvoiceOpJnlServiceImpl extends BaseServiceImpl<UserInvoiceOpJnlMapper, UserInvoiceOpJnl, UserInvoiceOpJnlExample>
        implements UserInvoiceOpJnlService {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserInvoiceOpJnlServiceImpl.class);

    @Autowired
    UserInvoiceOpJnlMapper userInvoiceOpJnlDao;

    @Autowired
    ItcsTransJnlMapper itcsTransJnlDao;

    @Override
    public Integer addUserInvoiceOpJnl(UserInvoiceOpJnl userInvoiceOpJnl) {

        Integer result = userInvoiceOpJnlDao.insertSelective(userInvoiceOpJnl);

        List<String> trannos = Arrays.asList(userInvoiceOpJnl.getTripCnt().split(","));

        //更新交易记录表中订单开票状态
        ItcsTransJnl itcsTransJnl = new ItcsTransJnl();
        itcsTransJnl.setInvoiceState(new Byte("2"));
        ItcsTransJnlExample itcsTransJnlExample = new ItcsTransJnlExample();
        itcsTransJnlExample.createCriteria().andTransNoIn(trannos);
        Integer transResult =  itcsTransJnlDao.updateByExampleSelective(itcsTransJnl,itcsTransJnlExample);

        return transResult;
    }
}